﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     Favorite业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class FavoriteSqlMapDao : BaseSqlMapDao, IFavoriteDao
    {
        private static FavoriteSqlMapDao instance = null;
        private static object syncRoot = new object();

        private FavoriteSqlMapDao()
        {
            //
            // TODO: 此处添加FavoriteSqlMapDao的构造函数
            //
        }
        public static IFavoriteDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new FavoriteSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectFavoriteByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<Favorite> GetList()
        {
            try
            {
                return ExecuteQueryForList<Favorite>("SelectFavorite", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<Favorite> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<Favorite>("SelectFavoriteByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="FavoriteID"></param>
        /// <returns></returns>
        public Favorite GetDetail(System.String favoriteid)
        {
            try
            {
                return ExecuteQueryForObject<Favorite>("SelectFavorite", favoriteid) as Favorite;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="favorite"></param>
        /// <returns></returns>
        public object Add(Favorite favorite)
        {
            //int id = GetId("Favorite");
            //favorite.FavoriteID = id;

            try
            {
                return ExecuteInsert("InsertFavorite", favorite);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="favorite"></param>
        /// <returns></returns>
        public int Update(Favorite favorite)
        {
            try
            {
                return ExecuteUpdate("UpdateFavorite", favorite);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="favorite"></param>
        /// <returns></returns>
        public int Delete(Favorite favorite)
        {
            try
            {
                return ExecuteDelete("DeleteFavorite", favorite);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pager"></param>
        /// <returns></returns>
        public IList<Favorite> GetPagedList(NetPager pager)
        {
            try
            {
                return ExecuteQueryForList<Favorite>("GetPagedFavoriteList", pager);
            }
            catch 
            {
                
                throw;
            }
        }


       /// <summary>
       /// 通过服务ID得到被收藏数
       /// 创建人：Wilson
       /// 创建时间：2011-10-27
       /// </summary>
       /// <param name="serviceId"></param>
       /// <returns></returns>
        public int GetSFavCountByServiceId(string serviceId)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectFavCountByServiceId", serviceId);
            }
            catch (Exception)
            {
                
                throw;
            }
        }

      
    }
}
